i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n G e o F r o m H i t ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n G e o F r o m H i t ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n G e o Q u e r y C o u n t y ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n G e o Q u e r y C o u n t y ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n G e o Q u e r y S t a t e ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n G e o Q u e r y S t a t e ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n G e o Q u e r y Z I P ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n G e o Q u e r y Z I P ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n G e o c o d e ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n G e o c o d e ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n G e o c o d e C l o s e s t A d d r e s s ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n G e o c o d e C l o s e s t A d d r e s s ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n G e o c o d e I n t e r s e c t i o n ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n G e o c o d e I n t e r s e c t i o n ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n L i n e D i s t a n c e ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n L i n e D i s t a n c e ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n L i n e R a t i o ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n L i n e R a t i o ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n P o i n t D i s t a n c e F r o m L i n e ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n P o i n t D i s t a n c e F r o m L i n e ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n P o i n t F r o m C h a i n R a t i o ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n P o i n t F r o m C h a i n R a t i o ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n R e v e r s e G e o c o d e ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n R e v e r s e G e o c o d e ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ f n T o t a l C h a i n D i s t a n c e ] ' )   a n d   x t y p e   i n   ( N ' F N ' ,   N ' I F ' ,   N ' T F ' ) ) 
 
 d r o p   f u n c t i o n   [ d b o ] . [ f n T o t a l C h a i n D i s t a n c e ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ F I P S 5 5 ] ' )   a n d   O B J E C T P R O P E R T Y ( i d ,   N ' I s U s e r T a b l e ' )   =   1 ) 
 
 d r o p   t a b l e   [ d b o ] . [ F I P S 5 5 ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ T I G E R _ 0 1 ] ' )   a n d   O B J E C T P R O P E R T Y ( i d ,   N ' I s U s e r T a b l e ' )   =   1 ) 
 
 d r o p   t a b l e   [ d b o ] . [ T I G E R _ 0 1 ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ T I G E R _ 0 1 _ M I N _ T E M P ] ' )   a n d   O B J E C T P R O P E R T Y ( i d ,   N ' I s U s e r T a b l e ' )   =   1 ) 
 
 d r o p   t a b l e   [ d b o ] . [ T I G E R _ 0 1 _ M I N _ T E M P ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ T I G E R _ 0 2 ] ' )   a n d   O B J E C T P R O P E R T Y ( i d ,   N ' I s U s e r T a b l e ' )   =   1 ) 
 
 d r o p   t a b l e   [ d b o ] . [ T I G E R _ 0 2 ] 
 
 G O 
 
 
 
 i f   e x i s t s   ( s e l e c t   *   f r o m   d b o . s y s o b j e c t s   w h e r e   i d   =   o b j e c t _ i d ( N ' [ d b o ] . [ T I G E R _ T Y P E S ] ' )   a n d   O B J E C T P R O P E R T Y ( i d ,   N ' I s U s e r T a b l e ' )   =   1 ) 
 
 d r o p   t a b l e   [ d b o ] . [ T I G E R _ T Y P E S ] 
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O F F   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 C R E A T E   F U N C T I O N   d b o . f n G e o F r o m H i t 
 
 	 ( 
 
 	 	 @ N u m b e r   i n t , 
 
 	 	 @ T L I D   v a r c h a r ( 5 0 ) , 
 
 	 	 @ F r o m A d d R   i n t ,   
 
 	 	 @ F r o m A d d L   i n t ,   
 
 	 	 @ T o A d d R   i n t , 
 
 	 	 @ T o A d d L   i n t ,   
 
 	 	 @ z i p L   i n t ,   
 
 	 	 @ z i p R   i n t , 
 
 	 	 @ F r o m L n g   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ F r o m L a t   d e c i m a l ( 9 , 6 ) , 
 
   	 	 @ L o n g 1   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 1   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 2   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 2   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 3   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 3   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 4   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 4   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 5   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 5   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 6   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 6   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 7   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 7   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 8   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 8   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 9   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 9   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 1 0   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 1 0   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ T o L n g   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ T o L a t   d e c i m a l ( 9 , 6 ) 
 
 	 ) 
 
 R E T U R N S     @ L o c a t i o n   T A B L E   
 
 	 ( 
 
 	 L o n g i t u d e   D e c i m a l ( 9 , 6 ) ,   
 
 	 L a t i t u d e   D e c i m a l ( 9 , 6 ) , 
 
 	 Z I P   i n t , 
 
 	 T L I D   v a r c h a r ( 5 0 ) 
 
 	 ) 
 
 A S 
 
 	 B E G I N 
 
 	 
 
 	 d e c l a r e   @ l a t T o t a l   d e c i m a l ( 9 , 6 )   
 
 	 d e c l a r e   @ l n g T o t a l   d e c i m a l ( 9 , 6 )   
 
 	 s e t   @ l a t T o t a l   =   0 
 
 	 s e t   @ l n g T o t a l   =   0 
 
 
 
 	 
 
 	 s e l e c t   @ l n g T o t a l   =   T o t a l L o n g ,   @ l a t T o t a l   =   T o t a l L a t   f r o m   
 
 	 f n T o t a l C h a i n D i s t a n c e ( @ F r o m L n g ,   @ F r o m L a t ,   @ L o n g 1 , @ L a t 1 , @ L o n g 2 , @ L a t 2 , @ L o n g 3 , @ L a t 3 , @ L o n g 4 , @ L a t 4 , @ L o n g 5 , @ L a t 5 , @ L o n g 6 , @ L a t 6 , @ L o n g 7 , @ L a t 7 , @ L o n g 8 , @ L a t 8 , @ L o n g 9 , @ L a t 9 , @ L o n g 1 0 , @ L a t 1 0 ,   @ T o l n g , @ T o L a t ) 
 
 
 
 
 
 	 
 
 	 d e c l a r e   @ r e l   d e c i m a l ( 9 , 6 ) 
 
 	 
 
 	 d e c l a r e   @ d e c 1   d e c i m a l ( 2 0 , 6 ) 
 
 	 d e c l a r e   @ d e c 2   d e c i m a l ( 2 0 , 6 ) 
 
 	 
 
 	 - - w h i c h   s i d e   o f   t h e   s t r e e t   d o   w e   u s e ? 
 
 	 d e c l a r e   @ A d d S t a r t   i n t 
 
 	 d e c l a r e   @ A d d E n d   i n t 
 
 	 d e c l a r e   @ u s e z i p   i n t 
 
 
 
 	 d e c l a r e   @ u s e L e f t   i n t 
 
 	 d e c l a r e   @ u s e R i g h t   i n t 
 
 	 s e t   @ u s e L e f t   =   0 
 
 	 s e t   @ u s e R i g h t   =   0 
 
 	 
 
 	 - - w e   n e e d   t o   t h r o w   o u t   s i d e s   i f   t h e y   a r e   n o t   i n   r a n g e   o r   w e r e   n u l l   i n   t h e   d b   ( - 1 ) 
 
 	 i f   @ F r o m A d d R   =   - 1   O R   ( ( @ N u m b e r   n o t   b e t w e e n   @ f r o m a d d r   a n d   @ t o a d d r )   a n d   ( @ N u m b e r   n o t   b e t w e e n   @ t o a d d r   a n d   @ f r o m a d d r ) ) 
 
 	 b e g i n 
 
 	 	 s e t   @ u s e R i g h t   =   - 1 
 
 	 	 s e t   @ u s e L e f t   =   1 
 
 	 e n d 
 
 	 
 
 	 i f   @ F r o m A d d L   =   - 1   O R   ( ( @ N u m b e r   n o t   b e t w e e n   @ f r o m a d d L   a n d   @ t o a d d L )   a n d   ( @ N u m b e r   n o t   b e t w e e n   @ t o a d d L   a n d   @ f r o m a d d L ) ) 
 
 	 b e g i n 
 
 	 	 s e t   @ u s e L e f t   =   - 1 
 
 	 	 s e t   @ u s e R i g h t   =   1 
 
 	 e n d 
 
 
 
 	 - - m a k e   s u r e   t h e   n u m b e r   w a s   n o t   n u l l ,   t h e   p a r i t y   m a t c h e s ,   a n d   t h a t   i t s   i n   r a n g e 
 
 	 i f   @ u s e R i g h t   < >   - 1   a n d   ( ( @ F r o m A d d R   %   2 )   =   ( @ N u m b e r   %   2 )   O R   @ u s e L e f t   =   - 1 ) 
 
 	 b e g i n 
 
 	 	 - - u s e   t h e   r i g h t   s i d e 
 
 	 	 s e t   @ A d d S t a r t   =   @ F r o m A d d r 
 
 	 	 s e t   @ A d d E n d   =   @ T o A d d r 
 
 	 	 s e t   @ u s e z i p   =   @ z i p r 
 
 	 e n d 
 
 	 e l s e 
 
 	 b e g i n 
 
 	 	 - - u s e   t h e   l e f t   s i d e 
 
 	 	 s e t   @ A d d S t a r t   =   @ F r o m A d d L 
 
 	 	 s e t   @ A d d E n d   =   @ T o A d d L 
 
 	 	 s e t   @ u s e z i p   =   @ z i p L 
 
 	 
 
 	 e n d 
 
 
 
 
 
 
 
 	 s e t   @ d e c 1   =   @ A d d E n d   -   @ N u m b e r 
 
 	 s e t   @ d e c 2   =   @ A d d E n d   -   @ A d d S t a r t 
 
 
 
 
 
 
 
 	 s e t   @ r e l   =   ( @ d e c 1   /   @ d e c 2 ) 
 
 	 i f   @ r e l   =   1 
 
 	 b e g i n 
 
 	 	 - - r e t u r n   s t a r t 
 
 	 	 I N S E R T   i n t o   @ L o c a t i o n   
 
 	 	 S E L E C T     @ F r o m L n g , @ F r o m L a t , @ u s e z i p , @ T L I D 
 
 	 	 r e t u r n 
 
 	 e n d 
 
 	 
 
 	 i f   @ r e l   =   0 
 
 	 b e g i n 
 
 	 	 - - r e t u r n   e n d 
 
 	 	 I N S E R T   i n t o   @ L o c a t i o n   
 
 	 	 S E L E C T     @ T o L n g , @ T o L a t , @ u s e z i p , @ T L I D 
 
 	 	 r e t u r n 
 
 	 e n d 
 
 	 
 
 	 
 
 	 d e c l a r e   @ l a t   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ l o n   d e c i m a l ( 9 , 6 ) 
 
 	 
 
 	 - - T h i s   i s   t h e   s t r a i g h t   l i n e   c a l c u l a t i o n ,   l e a v i n g   i t   i n   f o r   t e s t i n g 
 
 	 s e t   @ l a t   =   @ F r o m L a t   +   ( @ r e l   *   @ l a t T o t a l ) 
 
 	 s e t   @ l o n   =   @ F r o m L n g   +   ( @ r e l   *   @ l n g T o t a l ) 
 
 	 
 
 
 
 	 - - - - E n d   p o i n t   o f   e n t i r e   c h a i n   i f   t h i s   w a s   a   s t r a i g h t   l i n e   s o   w e   c a n   c a l c u l a t e   t o t a l   d i s t a n c e 
 
 	 d e c l a r e   @ t e m p E n d L a t   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ t e m p E n d L n g   d e c i m a l ( 9 , 6 ) 
 
 	 s e t   @ t e m p E n d L a t   =   @ f r o m L a t   +   @ l a t T o t a l 
 
 	 s e t   @ t e m p E n d L n g   =   @ f r o m L n g   +   @ l n g T o t a l 
 
 
 
 	 d e c l a r e   @ t o t a l D i s t   d e c i m a l ( 2 0 , 6 ) 
 
 	 s e t   @ t o t a l D i s t   =   d b o . f n L i n e D i s t a n c e ( @ f r o m L n g ,   @ f r o m L a t , @ t e m p E n d L n g ,   @ t e m p E n d L a t ) 
 
 
 
 	 - - N o w   w e   n e e d   t o   g o   b a c k   t h r o u g h   t h e   c h a i n 
 
 	 - - W e   h a v e   t h e   p e r c e n t a g e   w e   n e e d   t o   t r a v e l   ( @ r e l )   a n d   t h e   t o t a l   d i s t a n c e   ( @ t o t a l D i s t ) 	 
 
 	 - - F o l l o w   t h e   c h a i n   u n t i l   w e   f i n d   o u r   p o i n t 	 
 
 	 
 
 	 s e l e c t   @ l o n   =   L o n g i t u d e ,   @ l a t   =   L a t i t u d e   f r o m   
 
 	 d b o . f n P o i n t F r o m C h a i n R a t i o ( @ t o t a l D i s t ,   @ r e l ,   @ F r o m L n g ,   @ F r o m L a t ,   @ L o n g 1 , @ L a t 1 , @ L o n g 2 , @ L a t 2 , @ L o n g 3 , @ L a t 3 , @ L o n g 4 , @ L a t 4 , @ L o n g 5 , @ L a t 5 , @ L o n g 6 , @ L a t 6 , @ L o n g 7 , @ L a t 7 , @ L o n g 8 , @ L a t 8 , @ L o n g 9 , @ L a t 9 , @ L o n g 1 0 , @ L a t 1 0 ,   @ T o l n g , @ T o L a t ) 
 
 
 
 	 I n s e r t   i n t o   @ L o c a t i o n 
 
 	 	 S e l e c t   @ l o n , @ l a t , @ u s e z i p , @ T L I D 
 
 
 
 	 R E T U R N 
 
 	 E N D 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O F F   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 C R E A T E       F U N C T I O N   d b o . f n G e o Q u e r y C o u n t y 
 
 	 ( @ D i r P r e f i x   v a r c h a r ( 2 )   =   ' ' ,   @ N u m b e r   i n t ,   @ S t r e e t N a m e   v a r c h a r ( 5 0 ) ,   @ S t r e e t T y p e   v a r c h a r ( 5 0 ) ,   @ D i r S u f f i x   v a r c h a r ( 2 )   =   ' ' ,   @ F i p s S t a t e C o d e   i n t ,   @ F i p s C o u n t y C o d e   i n t ) 
 
 
 
 R E T U R N S   @ G E O   T A B L E   
 
 ( 
 
 F r o m A d d R   i n t , 
 
 F r o m A d d L   i n t , 
 
 T o A d d R   i n t , 
 
 T o A d d L   i n t , 
 
 z i p L   i n t , 
 
 z i p R   i n t , 
 
 T o L a t   d e c i m a l ( 9 , 6 ) , 
 
 T o L n g   d e c i m a l ( 9 , 6 ) , 
 
 F r o m L n g   d e c i m a l ( 9 , 6 ) , 
 
 F r o m L a t   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 1   d e c i m a l ( 9 , 6 ) , 
 
 L a t 1   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 2   d e c i m a l ( 9 , 6 ) , 
 
 L a t 2   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 3   d e c i m a l ( 9 , 6 ) , 
 
 L a t 3   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 4   d e c i m a l ( 9 , 6 ) , 
 
 L a t 4   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 5   d e c i m a l ( 9 , 6 ) , 
 
 L a t 5   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 6   d e c i m a l ( 9 , 6 ) , 
 
 L a t 6   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 7   d e c i m a l ( 9 , 6 ) , 
 
 L a t 7   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 8   d e c i m a l ( 9 , 6 ) , 
 
 L a t 8   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 9   d e c i m a l ( 9 , 6 ) , 
 
 L a t 9   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 1 0   d e c i m a l ( 9 , 6 ) , 
 
 L a t 1 0   d e c i m a l ( 9 , 6 ) , 
 
 T L I D   v a r c h a r ( 5 0 ) 
 
 ) 
 
 A S 
 
 	 B E G I N 
 
 	 
 
 	 d e c l a r e   @ t o d e c i m a l   d e c i m a l ( 9 , 6 ) 
 
 	 s e t   @ t o d e c i m a l   =   0 . 0 0 0 0 0 1 
 
 
 
 I N S E R T   I N T O   @ G E O 
 
 s e l e c t   t o p   1   
 
 	 i s n u l l ( t 1 . f r a d d r , - 1 )   ,   i s n u l l ( t 1 . f r a d d l , - 1 )   ,   i s n u l l ( t 1 . t o a d d r , - 1 ) ,   i s n u l l ( t 1 . t o a d d l , - 1 ) ,   t 1 . z i p l ,   t 1 . z i p r ,   t 1 . t o l a t   *   @ t o d e c i m a l ,   t 1 . t o l o n g   *   @ t o d e c i m a l ,   t 1 . f r l o n g   *   @ t o d e c i m a l ,   t 1 . f r l a t   *   @ t o d e c i m a l ,   
 
 	 	 i s n u l l ( t 2 . l o n g 1 , 0 )     *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 1 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 2 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 2 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 3 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 3 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 4 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 4 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 5 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 5 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 6 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 6 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 7 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 7 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 8 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 8 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 9 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 9 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 1 0 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 1 0 , 0 )   *   @ t o d e c i m a l ,   t 1 . T L I D 
 
 	     f r o m   T I G E R _ 0 1   t 1   w i t h   ( n o l o c k )   l e f t   o u t e r   j o i n   T I G E R _ 0 2   t 2     w i t h   ( n o l o c k )   o n   t 1 . t l i d   =   t 2 . t l i d     w h e r e   f e n a m e   =   @ S t r e e t N a m e   a n d   f e t y p e   =   @ S t r e e t T y p e   a n d   f e d i r p   =   @ D i r P r e f i x   a n d   f e d i r s   =   @ D i r S u f f i x   a n d   ( s t a t e l   =   @ F i p s S t a t e C o d e   o r   s t a t e r   = @ F i p s S t a t e C o d e )   a n d   ( c o u n t y l   =   @ F i p s C o u n t y C o d e   o r   c o u n t y r   = @ F i p s C o u n t y C o d e ) 
 
               a n d   ( ( f r a d d l   < =   @ N u m b e r   a n d   t o a d d l   > =   @ N u m b e r )   o r   ( f r a d d l   > =   @ N u m b e r   a n d   t o a d d l   < =   @ N u m b e r   ) 
 
                 O R   ( f r a d d r   < =   @ N u m b e r   a n d   t o a d d r   > =   @ N u m b e r )   O R   ( f r a d d r   > =   @ N u m b e r   a n d   t o a d d r   < =   @ N u m b e r )   ) 
 
 
 
 	 R E T U R N 
 
 	 E N D 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O F F   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 C R E A T E       F U N C T I O N   d b o . f n G e o Q u e r y S t a t e 
 
 	 ( @ D i r P r e f i x   v a r c h a r ( 2 )   =   ' ' ,   @ N u m b e r   i n t ,   @ S t r e e t N a m e   v a r c h a r ( 5 0 ) ,   @ S t r e e t T y p e   v a r c h a r ( 5 0 ) ,   @ D i r S u f f i x   v a r c h a r ( 2 )   = ' ' ,   @ F i p s S t a t e C o d e   i n t ) 
 
 
 
 R E T U R N S   @ G E O   T A B L E   
 
 ( 
 
 F r o m A d d R   i n t , 
 
 F r o m A d d L   i n t , 
 
 T o A d d R   i n t , 
 
 T o A d d L   i n t , 
 
 z i p L   i n t , 
 
 z i p R   i n t , 
 
 T o L a t   d e c i m a l ( 9 , 6 ) , 
 
 T o L n g   d e c i m a l ( 9 , 6 ) , 
 
 F r o m L n g   d e c i m a l ( 9 , 6 ) , 
 
 F r o m L a t   d e c i m a l ( 9 , 6 ) , 
 
 
 
 L o n g 1   d e c i m a l ( 9 , 6 ) , 
 
 L a t 1   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 2   d e c i m a l ( 9 , 6 ) , 
 
 L a t 2   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 3   d e c i m a l ( 9 , 6 ) , 
 
 L a t 3   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 4   d e c i m a l ( 9 , 6 ) , 
 
 L a t 4   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 5   d e c i m a l ( 9 , 6 ) , 
 
 L a t 5   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 6   d e c i m a l ( 9 , 6 ) , 
 
 L a t 6   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 7   d e c i m a l ( 9 , 6 ) , 
 
 L a t 7   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 8   d e c i m a l ( 9 , 6 ) , 
 
 L a t 8   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 9   d e c i m a l ( 9 , 6 ) , 
 
 L a t 9   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 1 0   d e c i m a l ( 9 , 6 ) , 
 
 L a t 1 0   d e c i m a l ( 9 , 6 ) , 
 
 T L I D   v a r c h a r ( 5 0 ) 
 
 ) 
 
 A S 
 
 	 B E G I N 
 
 	 
 
 	 d e c l a r e   @ t o d e c i m a l   d e c i m a l ( 9 , 6 ) 
 
 	 s e t   @ t o d e c i m a l   =   0 . 0 0 0 0 0 1 
 
 
 
 I N S E R T   I N T O   @ G E O 
 
 s e l e c t   t o p   1   
 
 	 i s n u l l ( t 1 . f r a d d r , - 1 )   ,   i s n u l l ( t 1 . f r a d d l , - 1 )   ,   i s n u l l ( t 1 . t o a d d r , - 1 ) ,   i s n u l l ( t 1 . t o a d d l , - 1 ) ,   t 1 . z i p l ,   t 1 . z i p r ,   t 1 . t o l a t   *   @ t o d e c i m a l ,   t 1 . t o l o n g   *   @ t o d e c i m a l ,   t 1 . f r l o n g   *   @ t o d e c i m a l ,   t 1 . f r l a t   *   @ t o d e c i m a l ,   
 
 	 	 i s n u l l ( t 2 . l o n g 1 , 0 )     *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 1 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 2 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 2 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 3 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 3 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 4 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 4 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 5 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 5 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 6 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 6 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 7 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 7 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 8 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 8 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 9 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 9 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 1 0 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 1 0 , 0 )   *   @ t o d e c i m a l ,   t 1 . T L I D 
 
 	     f r o m   T I G E R _ 0 1   t 1   w i t h   ( n o l o c k )   l e f t   o u t e r   j o i n   T I G E R _ 0 2   t 2     w i t h   ( n o l o c k )   o n   t 1 . t l i d   =   t 2 . t l i d     w h e r e   f e n a m e   =   @ S t r e e t N a m e   a n d   f e t y p e   =   @ S t r e e t T y p e   a n d   f e d i r p   =   @ D i r P r e f i x   a n d   f e d i r s   =   @ D i r S u f f i x   a n d   ( s t a t e l   =   @ F i p s S t a t e C o d e   o r   s t a t e r   = @ F i p s S t a t e C o d e ) 
 
               a n d   ( ( f r a d d l   < =   @ N u m b e r   a n d   t o a d d l   > =   @ N u m b e r )   o r   ( f r a d d l   > =   @ N u m b e r   a n d   t o a d d l   < =   @ N u m b e r   ) 
 
                 O R   ( f r a d d r   < =   @ N u m b e r   a n d   t o a d d r   > =   @ N u m b e r )   O R   ( f r a d d r   > =   @ N u m b e r   a n d   t o a d d r   < =   @ N u m b e r )   ) 
 
 
 
 	 R E T U R N 
 
 	 E N D 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O F F   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 C R E A T E       F U N C T I O N   d b o . f n G e o Q u e r y Z I P 
 
 	 ( @ D i r P r e f i x   v a r c h a r ( 2 )   =   ' ' ,   @ N u m b e r   i n t ,   @ S t r e e t N a m e   v a r c h a r ( 5 0 ) ,   @ S t r e e t T y p e   v a r c h a r ( 5 0 ) ,   @ D i r S u f f i x   v a r c h a r ( 2 )   = ' ' ,   @ Z i p C o d e   i n t ) 
 
 
 
 R E T U R N S   @ G E O   T A B L E   
 
 ( 
 
 F r o m A d d R   i n t , 
 
 F r o m A d d L   i n t , 
 
 T o A d d R   i n t , 
 
 T o A d d L   i n t , 
 
 z i p L   i n t , 
 
 z i p R   i n t , 
 
 T o L a t   d e c i m a l ( 9 , 6 ) , 
 
 T o L n g   d e c i m a l ( 9 , 6 ) , 
 
 F r o m L n g   d e c i m a l ( 9 , 6 ) , 
 
 F r o m L a t   d e c i m a l ( 9 , 6 ) , 
 
 
 
 L o n g 1   d e c i m a l ( 9 , 6 ) , 
 
 L a t 1   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 2   d e c i m a l ( 9 , 6 ) , 
 
 L a t 2   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 3   d e c i m a l ( 9 , 6 ) , 
 
 L a t 3   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 4   d e c i m a l ( 9 , 6 ) , 
 
 L a t 4   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 5   d e c i m a l ( 9 , 6 ) , 
 
 L a t 5   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 6   d e c i m a l ( 9 , 6 ) , 
 
 L a t 6   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 7   d e c i m a l ( 9 , 6 ) , 
 
 L a t 7   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 8   d e c i m a l ( 9 , 6 ) , 
 
 L a t 8   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 9   d e c i m a l ( 9 , 6 ) , 
 
 L a t 9   d e c i m a l ( 9 , 6 ) , 
 
 L o n g 1 0   d e c i m a l ( 9 , 6 ) , 
 
 L a t 1 0   d e c i m a l ( 9 , 6 ) , 
 
 T L I D   v a r c h a r ( 5 0 ) 
 
 ) 
 
 A S 
 
 	 B E G I N 
 
 	 
 
 	 d e c l a r e   @ t o d e c i m a l   d e c i m a l ( 9 , 6 ) 
 
 	 s e t   @ t o d e c i m a l   =   0 . 0 0 0 0 0 1 
 
 
 
 I N S E R T   I N T O   @ G E O 
 
 s e l e c t   t o p   1   
 
 	 i s n u l l ( t 1 . f r a d d r , - 1 )   ,   i s n u l l ( t 1 . f r a d d l , - 1 )   ,   i s n u l l ( t 1 . t o a d d r , - 1 ) ,   i s n u l l ( t 1 . t o a d d l , - 1 ) ,   t 1 . z i p l ,   t 1 . z i p r ,   t 1 . t o l a t   *   @ t o d e c i m a l ,   t 1 . t o l o n g   *   @ t o d e c i m a l ,   t 1 . f r l o n g   *   @ t o d e c i m a l ,   t 1 . f r l a t   *   @ t o d e c i m a l ,   
 
 	 	 i s n u l l ( t 2 . l o n g 1 , 0 )     *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 1 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 2 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 2 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 3 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 3 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 4 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 4 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 5 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 5 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 6 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 6 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 7 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 7 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 8 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 8 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 9 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 9 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l o n g 1 0 , 0 )   *   @ t o d e c i m a l ,   i s n u l l ( t 2 . l a t 1 0 , 0 )   *   @ t o d e c i m a l ,   t 1 . T L I D 
 
 	     f r o m   T I G E R _ 0 1   t 1   w i t h   ( n o l o c k )   l e f t   o u t e r   j o i n   T I G E R _ 0 2   t 2     w i t h   ( n o l o c k )   o n   t 1 . t l i d   =   t 2 . t l i d     w h e r e   f e n a m e   =   @ S t r e e t N a m e   a n d   f e t y p e   =   @ S t r e e t T y p e   a n d   f e d i r p   =   @ D i r P r e f i x   a n d   f e d i r s   =   @ D i r S u f f i x   a n d   ( z i p l   =   @ Z i p C o d e   o r   z i p r   = @ Z i p C o d e ) 
 
               a n d   ( ( f r a d d l   < =   @ N u m b e r   a n d   t o a d d l   > =   @ N u m b e r )   o r   ( f r a d d l   > =   @ N u m b e r   a n d   t o a d d l   < =   @ N u m b e r   ) 
 
                 O R   ( f r a d d r   < =   @ N u m b e r   a n d   t o a d d r   > =   @ N u m b e r )   O R   ( f r a d d r   > =   @ N u m b e r   a n d   t o a d d r   < =   @ N u m b e r )   ) 
 
 
 
 	 R E T U R N 
 
 	 E N D 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O F F   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 / * 
 
    2 0 0 5   J o h n   S a m p l e 
 
 
 
         T h i s   p r o g r a m   i s   f r e e   s o f t w a r e ;   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
         i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
         t h e   F r e e   S o f t w a r e   F o u n d a t i o n ;   e i t h e r   v e r s i o n   2   o f   t h e   L i c e n s e ,   o r 
 
         ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
 
 
         T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
         b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
         M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
         G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
 
 
 * / 
 
 
 
 
 
 C R E A T E   F U N C T I O N   d b o . f n G e o c o d e   ( @ D i r P r e f i x   v a r c h a r ( 2 )   =   ' ' ,   @ N u m b e r   i n t ,   @ S t r e e t N a m e   v a r c h a r ( 5 0 ) ,   @ S t r e e t T y p e   v a r c h a r ( 5 0 ) ,   @ D i r S u f f i x   v a r c h a r ( 2 )   =   ' ' ,   @ Z i p C o d e   i n t   = - 1   ,   @ F i p s S t a t e C o d e   i n t = - 1 ,   @ F i p s C o u n t y C o d e   i n t   = - 1 ) 
 
 R E T U R N S   @ L o c a t i o n   T A B L E   
 
 	 ( 
 
 	 L o n g i t u d e   D e c i m a l ( 9 , 6 ) ,   
 
 	 L a t i t u d e   D e c i m a l ( 9 , 6 ) , 
 
 	 Z I P   i n t , 
 
 	 T L I D   v a r c h a r ( 5 0 ) 
 
 	 ) 
 
 A S 
 
 B E G I N 
 
 
 
 
 
 d e c l a r e   @ F r o m L a t   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ T o L a t   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ F r o m L n g   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ T o L n g   d e c i m a l ( 9 , 6 ) 
 
 
 
 d e c l a r e   @ T L I D   v a r c h a r ( 5 0 ) 
 
 
 
 d e c l a r e   @ F r o m A d d R   i n t 
 
 d e c l a r e   @ T o A d d R   i n t 
 
 d e c l a r e   @ F r o m A d d L   i n t 
 
 d e c l a r e   @ T o A d d L   i n t 
 
 
 
 d e c l a r e   @ z i p L   i n t 
 
 d e c l a r e   @ z i p R   i n t 
 
 
 
 - - w e   n e e d   1 0   l a t / l o n g   p a i r s   f o r   t y p e   2   r e c o r d s 
 
 d e c l a r e   @ L o n g 1   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L a t 1   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L o n g 2   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L a t 2   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L o n g 3   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L a t 3   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L o n g 4   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L a t 4   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L o n g 5   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L a t 5   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L o n g 6   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L a t 6   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L o n g 7   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L a t 7   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L o n g 8   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L a t 8   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L o n g 9   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L a t 9   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L o n g 1 0   d e c i m a l ( 9 , 6 ) 
 
 d e c l a r e   @ L a t 1 0   d e c i m a l ( 9 , 6 ) 
 
 
 
 d e c l a r e   @ q u e r y p i c k e d   i n t 
 
 s e t   @ q u e r y p i c k e d   =   0 
 
 
 
 d e c l a r e   @ t o d e c i m a l   d e c i m a l ( 9 , 6 ) 
 
 s e t   @ t o d e c i m a l   =   0 . 0 0 0 0 0 1 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 - - - w h i c h   q u e r y   d o   w e   u s e ? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 / * 
 
 T h i s   s e c t i o n   i s   r e s p o n s i b l e   f o r   f i n d i n g   a   s u i t a b l e   t i g e r   r e c o r d . 
 
 I f   a   h i t   i s   f o u n d   i t s   p a s s e d   o f f   t o   t h e   g e o c o d i n g   f u n c t i o n 
 
 * / 
 
 - - z i p   q u e r y 
 
 i f   ( @ Z i p C o d e   < >   - 1   a n d   @ q u e r y p i c k e d   =   0 ) 
 
 b e g i n 
 
 	 s e t   @ q u e r y p i c k e d   =   1 
 
 	 
 
 	 D E C L A R E   c 1   C U R S O R   F O R 
 
 	 	 s e l e c t   *   f r o m   f n G e o Q u e r y Z I P ( @ D i r P r e f i x ,   @ N u m b e r ,   @ S t r e e t N a m e , @ S t r e e t T y p e ,   @ D i r S u f f i x ,   @ Z i p C o d e ) 
 
 
 
 e n d 
 
 
 
 - - c o u n t y   q u e r y 
 
 i f   ( @ F i p s S t a t e C o d e   < >   - 1   a n d   @ F i p s C o u n t y C o d e   < >   - 1   a n d   @ q u e r y p i c k e d   =   0 ) 
 
 b e g i n 
 
 	 s e t   @ q u e r y p i c k e d   =   1 
 
 	 D E C L A R E   c 1   C U R S O R   F O R 
 
 	 s e l e c t   *   f r o m   f n G e o Q u e r y C o u n t y ( @ D i r P r e f i x ,   @ N u m b e r ,   @ S t r e e t N a m e , @ S t r e e t T y p e ,   @ D i r S u f f i x ,   @ F i p s S t a t e C o d e ,   @ F i p s C o u n t y C o d e ) 
 
 
 
 e n d 
 
 
 
 - - s t a t e   q u e r y 
 
 i f   ( @ F i p s S t a t e C o d e   < >   - 1   a n d   @ q u e r y p i c k e d   =   0 ) 
 
 b e g i n 
 
 	 s e t   @ q u e r y p i c k e d   =   1 
 
 	 D E C L A R E   c 1   C U R S O R   F O R 
 
 	 s e l e c t   *   f r o m   f n G e o Q u e r y S t a t e ( @ D i r P r e f i x ,   @ N u m b e r ,   @ S t r e e t N a m e , @ S t r e e t T y p e ,   @ D i r S u f f i x ,   @ F i p s S t a t e C o d e ) 
 
 e n d 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
 
 
 
 O P E N   c 1 
 
 
 
 F E T C H   N E X T   F R O M   c 1   I N T O   
 
 	 @ F r o m A d d R ,   @ F r o m A d d L ,   @ T o A d d R ,   @ T o A d d L ,   @ z i p L ,   @ z i p R ,   @ T o L a t ,   @ T o L n g ,   @ F r o m L n g ,   @ F r o m L a t , @ L o n g 1 ,   @ L a t 1 , @ L o n g 2 ,   @ L a t 2 , @ L o n g 3 ,   @ L a t 3 , @ L o n g 4 ,   @ L a t 4 , @ L o n g 5 ,   @ L a t 5 , @ L o n g 6 ,   @ L a t 6 , @ L o n g 7 ,   @ L a t 7 , @ L o n g 8 ,   @ L a t 8 , @ L o n g 9 ,   @ L a t 9 ,   @ L o n g 1 0 ,   @ L a t 1 0 ,   @ T L I D 
 
 
 
 i f   ( @ @ F E T C H _ S T A T U S   =   0 ) 
 
 B E G I N 
 
 	 
 
 	 / * 
 
 	 	 W e ' v e   g o t   a   h i t .   p a s s   t h e   i n f o   o f f   t o   t h e   g e o c o d i n g   f u n c t i o n .   W e   s h o u l d   b e   g u a r a n t e e d   a   l n g / l a t . 
 
 	 * / 
 
 
 
 	 - - - - - - - - - - - - - - - - - - - - - - - - 
 
 	 - -   S P E C I A L   C A S E 
 
 	 - -   I f   f r o m / t o   l a t   a n d   l o n g   a r e   e q u a l ,   t h i s   p o i n t   h a s   0   d i s t a n c e 
 
 	 i f   ( @ F r o m L a t   =   @ T o L a t   A N D   @ F r o m L n g   =   @ T o L n g ) 
 
 	 b e g i n 
 
 	 	 i n s e r t   i n t o   @ L o c a t i o n   
 
 	 	 	 s e l e c t   @ F r o m L n g ,   @ F r o m L a t ,   I s N u l l ( @ z i p L , @ z i p R ) , @ T L I D 
 
 	 	 	 r e t u r n 
 
 	 e n d 
 
 	 
 
 	 - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
 
 
 
 	 i n s e r t   i n t o   @ L o c a t i o n 
 
 	 	 s e l e c t   *   f r o m   f n G e o F r o m H i t ( @ N u m b e r , @ T L I D , @ F r o m A d d R , @ F r o m A d d l , @ T o A d d r , @ T o A d d L , @ Z i p L , @ Z i p R , @ F r o m L n g , @ F r o m L a t , @ L o n g 1 , @ L a t 1 , @ L o n g 2 , @ L a t 2 , @ L o n g 3 , @ L a t 3 , @ L o n g 4 , @ L a t 4 , @ L o n g 5 , @ L a t 5 , @ L o n g 6 , @ L a t 6 , @ L o n g 7 , @ L a t 7 , @ L o n g 8 , @ L a t 8 , @ L o n g 9 , @ L a t 9 , @ L o n g 1 0 , @ L a t 1 0 ,   @ T o l n g , @ T o L a t ) 
 
 	 
 
 E N D 
 
 
 
 
 
 C L O S E   c 1 
 
 D E A L L O C A T E   c 1 
 
 R E T U R N   
 
 	 
 
 E N D 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O F F   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 C R E A T E         f u n c t i o n   d b o . f n G e o c o d e C l o s e s t A d d r e s s 
 
 ( @ D i r P r e f i x   v a r c h a r ( 2 )   =   ' ' ,   @ N u m b e r   i n t ,   @ S t r e e t N a m e   v a r c h a r ( 5 0 ) ,   @ S t r e e t T y p e   v a r c h a r ( 5 0 ) ,   @ D i r S u f f i x   v a r c h a r ( 2 )   =   ' ' ,   @ Z i p C o d e   i n t ) 
 
 R E T U R N S   @ L o c a t i o n   T A B L E   
 
 	 ( 
 
 	 L o n g i t u d e   D e c i m a l ( 9 , 6 ) ,   
 
 	 L a t i t u d e   D e c i m a l ( 9 , 6 ) , 
 
 	 Z I P   i n t , 
 
 	 T L I D   v a r c h a r ( 5 0 ) 
 
 	 ) 
 
 a s 
 
 b e g i n 
 
 d e c l a r e   @ t o d e c i m a l   d e c i m a l ( 9 , 6 ) 
 
 s e t   @ t o d e c i m a l   =   0 . 0 0 0 0 0 1 
 
 
 
 i n s e r t   i n t o   @ L o c a t i o n 
 
 s e l e c t     f r l o n g   *   @ t o d e c i m a l ,   f r l a t   *   @ t o d e c i m a l ,   i s n u l l ( z i p l , z i p r ) , t l i d   f r o m   t i g e r _ 0 1   t 1   w h e r e   
 
 t 1 . f e n a m e   =   @ s t r e e t n a m e   a n d   t 1 . f e t y p e   =     @ s t r e e t t y p e   a n d   t 1 . f e d i r p   =   @ D i r P r e f i x   a n d   f e d i r s   =   @ D i r S u f f i x   a n d   ( z i p l   =   @ Z i p C o d e   o r   z i p r   = @ Z i p C o d e ) 
 
 a n d   a b s ( ( ( i s n u l l ( f r a d d r , f r a d d l )   +   i s n u l l ( f r a d d l , f r a d d r ) ) / 2 )   -   @ n u m b e r )   =   ( s e l e c t   m i n ( a b s ( ( ( i s n u l l ( f r a d d r , f r a d d l )   +   i s n u l l ( f r a d d l , f r a d d r ) ) / 2 )   -   @ n u m b e r ) )   f r o m   t i g e r _ 0 1   t 1   w h e r e   f e n a m e   =   @ s t r e e t n a m e   a n d   f e t y p e   =   @ s t r e e t t y p e     a n d   t 1 . f e d i r p   =   @ D i r P r e f i x   a n d   f e d i r s   =   @ D i r S u f f i x   a n d   ( z i p l   =   @ Z i p C o d e   o r   z i p r   = @ Z i p C o d e ) ) 
 
 
 
 - - W e ' r e   o n l y   c h e c k i n g   t h e   c l o s e s t   s t a r t   a d d r e s s   r e c o r d 
 
 - - t o   b e   m o r e   a c c u r a t e ,   w e   s h o u l d   t e s t   t h e   e n d   a d d r e s s e s   a l s o ,   t h e n   r e t u r n   t h e   l o n g / l a t   t h a t s   c l o s e s t 
 
 / * 
 
 U N I O N 
 
 s e l e c t     a b s ( f r a d d l   -   @ n u m b e r ) ,   t l i d ,   f e n a m e ,   f e t y p e ,   f r a d d r ,   t o a d d r ,   f r a d d l ,   t o a d d l   f r o m   t i g e r _ 0 1   t 1   w h e r e   
 
 t 1 . f e n a m e   =   @ s t r e e t n a m e   a n d   t 1 . f e t y p e   =     @ s t r e e t t y p e 
 
 a n d   a b s ( ( ( i s n u l l ( t o a d d r , t o a d d l )   +   i s n u l l ( t o a d d l , t o a d d r ) ) / 2 )   -   @ n u m b e r )   =   ( s e l e c t   m i n ( a b s ( ( ( i s n u l l ( t o a d d r , t o a d d l )   +   i s n u l l ( t o a d d l , t o a d d r ) ) / 2 )   -   @ n u m b e r ) )   f r o m   t i g e r _ 0 1   t 1   w h e r e   f e n a m e   =   @ s t r e e t n a m e   a n d   f e t y p e   =   @ s t r e e t t y p e   ) 
 
 * / 
 
 r e t u r n 
 
 e n d 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O F F   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 / * 
 
    2 0 0 5   J o h n   S a m p l e 
 
 
 
         T h i s   p r o g r a m   i s   f r e e   s o f t w a r e ;   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
         i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
         t h e   F r e e   S o f t w a r e   F o u n d a t i o n ;   e i t h e r   v e r s i o n   2   o f   t h e   L i c e n s e ,   o r 
 
         ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
 
 
         T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
         b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
         M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
         G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
 
 
 * / 
 
 / * 
 
 I f   r o a d s   a   a n d   b   i n t e r s e c t ,   w e   s h o u l d   f i n d   o n e   o f   t h e   f o l l o w i n g : 
 
 a . f r l a t   &   a . f r l o n g   =   b . f r l a t   &   b . f r l o n g 
 
 o r 
 
 a . f r l a t   &   a . f r l o n g   =   b . t o l a t   &   b . t o l o n g 
 
 o r 
 
 a . t o l a t   &   a . t o l o n g   =   b . f r l a t   b   a . f r l o n g 
 
 o r 
 
 a . t o l a t   &   a . t o l o n g   =   b . t o l a t   &   b . t o l o n g 
 
 
 
 * / 
 
 
 
 C R E A T E       F U N C T I O N   d b o . f n G e o c o d e I n t e r s e c t i o n 
 
 ( 
 
 @ D i r P r e f i x A   v a r c h a r ( 2 )   =   ' ' ,     @ S t r e e t N a m e A   v a r c h a r ( 5 0 ) ,   @ S t r e e t T y p e A   v a r c h a r ( 5 0 ) ,   @ D i r S u f f i x A   v a r c h a r ( 2 )   = ' ' ,   @ Z i p A   i n t , 
 
 @ D i r P r e f i x B   v a r c h a r ( 2 )   =   ' ' ,     @ S t r e e t N a m e B   v a r c h a r ( 5 0 ) ,   @ S t r e e t T y p e B   v a r c h a r ( 5 0 ) ,   @ D i r S u f f i x B   v a r c h a r ( 2 )   = ' ' ,   @ Z i p B   i n t 
 
 ) 
 
 R E T U R N S   @ L o c a t i o n   T A B L E   
 
 	 ( 
 
 	 L o n g i t u d e   D e c i m a l ( 9 , 6 ) ,   
 
 	 L a t i t u d e   D e c i m a l ( 9 , 6 ) 
 
 	 ) 
 
 A S 
 
 B E G I N 
 
 
 
 d e c l a r e   @ t o d e c i m a l   d e c i m a l ( 9 , 6 ) 
 
 s e t   @ t o d e c i m a l   =   0 . 0 0 0 0 0 1 
 
 
 
 I N S E R T   i n t o   @ L o c a t i o n   
 
 s e l e c t   f r l o n g   *   @ t o d e c i m a l   a s   L o n g i t u d e ,   f r l a t   *   @ t o d e c i m a l     a s   L a t i t u d e   f r o m   t i g e r _ 0 1   t 1 a   w h e r e   t 1 a . f e n a m e   =   @ S t r e e t N a m e A   a n d   t 1 a . f e t y p e   =   @ S t r e e t T y p e A   a n d   t 1 a . f e d i r p   =   @ D i r P r e f i x A   a n d   t 1 a . f e d i r s   =   @ D i r S u f f i x A   a n d   ( t 1 a . z i p l   =   @ Z i p A   o r   t 1 a . z i p r   = @ Z i p A ) 
 
 a n d   
 
 ( 
 
 e x i s t s ( s e l e c t   1   f r o m   t i g e r _ 0 1   t 1 b   w h e r e   t 1 b . f e n a m e   =   @ S t r e e t N a m e B   a n d   t 1 b . f e t y p e   =   @ S t r e e t T y p e B   a n d   ( t 1 b . z i p l   =   @ Z i p B   o r   t 1 b . z i p r   = @ Z i p B )   a n d   t 1 b . f e d i r p   =   @ D i r P r e f i x B   a n d   t 1 b . f e d i r s   =   @ D i r S u f f i x B   a n d   t 1 b . f r l a t =   t 1 a . f r l a t   a n d   t 1 b . f r l o n g =   t 1 a . f r l o n g ) 
 
 o r   
 
 e x i s t s ( s e l e c t   1   f r o m   t i g e r _ 0 1   t 1 b   w h e r e   t 1 b . f e n a m e   =   @ S t r e e t N a m e B   a n d   t 1 b . f e t y p e   =   @ S t r e e t T y p e B   a n d   ( t 1 b . z i p l   =   @ Z i p B   o r   t 1 b . z i p r   = @ Z i p B )   a n d   t 1 b . f e d i r p   =   @ D i r P r e f i x B   a n d   t 1 b . f e d i r s   =   @ D i r S u f f i x B   a n d   t 1 b . t o l a t =   t 1 a . f r l a t   a n d   t 1 b . t o l o n g =   t 1 a . f r l o n g ) 
 
 ) 
 
 U N I O N 
 
 s e l e c t   t o l o n g   *   @ t o d e c i m a l   a s   L o n g i t u d e ,   t o l a t   *   @ t o d e c i m a l   a s   L a t i t u d e   f r o m   t i g e r _ 0 1   t 1 a   w h e r e   t 1 a . f e n a m e   =   @ S t r e e t N a m e A   a n d   t 1 a . f e t y p e   =   @ S t r e e t T y p e A   a n d   t 1 a . f e d i r p   =   @ D i r P r e f i x A   a n d   t 1 a . f e d i r s   =   @ D i r S u f f i x A   a n d   ( t 1 a . z i p l   =   @ Z i p A   o r   t 1 a . z i p r   = @ Z i p A ) 
 
 a n d   
 
 ( 
 
 e x i s t s ( s e l e c t   1   f r o m   t i g e r _ 0 1   t 1 b   w h e r e   t 1 b . f e n a m e   =   @ S t r e e t N a m e B   a n d   t 1 b . f e t y p e   =   @ S t r e e t T y p e B   a n d   ( t 1 b . z i p l   =   @ Z i p B   o r   t 1 b . z i p r   = @ Z i p B )   a n d   t 1 b . f e d i r p   =   @ D i r P r e f i x B   a n d   t 1 b . f e d i r s   =   @ D i r S u f f i x B   a n d   t 1 b . f r l a t =   t 1 a . t o l a t   a n d   t 1 b . f r l o n g =   t 1 a . t o l o n g ) 
 
 o r   
 
 e x i s t s ( s e l e c t   1   f r o m   t i g e r _ 0 1   t 1 b   w h e r e   t 1 b . f e n a m e   =   @ S t r e e t N a m e B   a n d   t 1 b . f e t y p e   =   @ S t r e e t T y p e B   a n d   ( t 1 b . z i p l   =   @ Z i p B   o r   t 1 b . z i p r   = @ Z i p B )   a n d   t 1 b . f e d i r p   =   @ D i r P r e f i x B   a n d   t 1 b . f e d i r s   =   @ D i r S u f f i x B   a n d   t 1 b . t o l a t =   t 1 a . t o l a t   a n d   t 1 b . t o l o n g =   t 1 a . t o l o n g ) 
 
 ) 
 
 
 
 
 
 r e t u r n 
 
 E N D 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O N   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 C R E A T E     F U N C T I O N   d b o . f n L i n e D i s t a n c e 
 
 	 ( 
 
 	 
 
 	 @ x 1   d e c i m a l ( 9 , 6 ) , 
 
 	 @ y 1   d e c i m a l ( 9 , 6 ) , 
 
 	 @ x 2   d e c i m a l ( 9 , 6 ) , 
 
 	 @ y 2   d e c i m a l ( 9 , 6 ) 
 
 	 ) 
 
 R E T U R N S   d e c i m a l ( 2 0 , 6 ) 
 
 A S 
 
 	 B E G I N 
 
 	 	 
 
 
 
 
 
 	 d e c l a r e   @ d x   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ d y   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ t e m p   d e c i m a l ( 2 0 , 6 ) 
 
 	 	 
 
 	 	 s e t   @ d x   =   @ x 2   -   @ x 1 
 
 	 	 s e t   @ d y   =   @ y 2   -   @ y 1 
 
 	   s e t   @ t e m p   =   s q r t ( ( @ d x * @ d x )   +   ( @ d y * @ d y ) ) 
 
 	 R E T U R N   @ t e m p 
 
 
 
 	 E N D 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O N   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 C R E A T E   F U N C T I O N   d b o . f n L i n e R a t i o 
 
 	 ( 
 
 	 
 
 	 @ T o t a l L e n g t h   d e c i m a l ( 9 , 6 ) , 
 
 	 @ S e g m e n t L e n g t h   d e c i m a l ( 9 , 6 ) 
 
 	 
 
 	 ) 
 
 R E T U R N S   d e c i m a l ( 9 , 6 ) 
 
 A S 
 
 	 B E G I N 
 
 	 	 
 
 	 R E T U R N   @ S e g m e n t L e n g t h   /   @ T o t a l L e n g t h 
 
 	 
 
 	 E N D 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O N   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 C R E A T E     F U N C T I O N   d b o . f n P o i n t D i s t a n c e F r o m L i n e 
 
 	 ( 
 
 	 
 
 	 @ x 1   d e c i m a l ( 9 , 6 ) , 
 
 	 @ y 1   d e c i m a l ( 9 , 6 ) , 
 
 	 @ x 2   d e c i m a l ( 9 , 6 ) , 
 
 	 @ y 2   d e c i m a l ( 9 , 6 ) , 
 
 	 @ P o i n t X   d e c i m a l ( 9 , 6 ) , 
 
 	 @ P o i n t Y   d e c i m a l ( 9 , 6 ) 
 
 	 ) 
 
 R E T U R N S   d e c i m a l ( 2 0 , 6 ) 
 
 A S 
 
 	 B E G I N 
 
 	 	 
 
 
 
 
 
 	 d e c l a r e   @ d x   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ d y   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ t e m p   d e c i m a l ( 2 0 , 6 ) 
 
 	 d e c l a r e   @ d i s t a n c e   d e c i m a l ( 9 , 6 ) 	 
 
 
 
 	 	 s e t   @ d x   =   @ x 2   -   @ x 1 
 
 	 	 s e t   @ d y   =   @ y 2   -   @ y 1 
 
 	   s e t   @ t e m p   =   s q r t ( ( @ d x * @ d x )   +   ( @ d y * @ d y ) ) 
 
 	 
 
 	 s e t   @ d i s t a n c e   =     ( @ d x * ( @ P o i n t Y   -   @ y 1 )   -   @ d y * ( @ P o i n t X   -   @ x 1 ) ) / @ t e m p 
 
 
 
 	 R E T U R N   @ d i s t a n c e 
 
 
 
 	 E N D 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O F F   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 
 
 / * 
 
    2 0 0 5   J o h n   S a m p l e 
 
 
 
         T h i s   p r o g r a m   i s   f r e e   s o f t w a r e ;   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
         i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
         t h e   F r e e   S o f t w a r e   F o u n d a t i o n ;   e i t h e r   v e r s i o n   2   o f   t h e   L i c e n s e ,   o r 
 
         ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
 
 
         T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
         b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
         M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
         G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
 
 
 * / 
 
 C R E A T E   F U N C T I O N   d b o . f n P o i n t F r o m C h a i n R a t i o 
 
 	 ( 
 
 	 	 @ T o t a l L e n g t h   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ R a t i o   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ F r o m L n g   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ F r o m L a t   d e c i m a l ( 9 , 6 ) , 
 
   	 	 @ L o n g 1   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 1   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 2   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 2   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 3   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 3   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 4   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 4   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 5   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 5   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 6   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 6   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 7   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 7   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 8   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 8   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 9   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 9   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L o n g 1 0   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ L a t 1 0   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ T o L n g   d e c i m a l ( 9 , 6 ) , 
 
 	 	 @ T o L a t   d e c i m a l ( 9 , 6 ) 
 
 	 ) 
 
 
 
 R E T U R N S   @ L o n g L a t     T A B L E 
 
 	 ( 
 
 	 L o n g i t u d e   d e c i m a l ( 9 , 6 ) ,   
 
 	 L a t i t u d e   d e c i m a l ( 9 , 6 ) 
 
 	 ) 
 
 A S 
 
 B E G I N 
 
 	 
 
 	 - - b u f f e r   f o r   l a s t   x , y   c o o r d s 
 
 	 d e c l a r e   @ l a s t L n g   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ l a s t L a t   d e c i m a l ( 9 , 6 ) 
 
 
 
 	 s e t   @ l a s t L n g   =   @ f r o m L n g 
 
 	 s e t   @ l a s t L a t   =   @ f r o m L a t 	 
 
 
 
 	 d e c l a r e   @ f o u n d   i n t 
 
 	 s e t   @ f o u n d   =   0 
 
 
 
 	 d e c l a r e   @ t o t a l R a t i o   d e c i m a l ( 9 , 6 ) - - T r a c k s   t h e   t o t a l   p e r c e n t a g e   o f   t h e   l i n e   
 
 	 d e c l a r e   @ t o t a l T r a v e l   d e c i m a l ( 9 , 6 ) - - T r a c k s   t h e   t o t a l   d i s t a n c e   w e   h a v e   t r a v e l l e d 
 
 	 d e c l a r e   @ t r a v e l T a r g e t   d e c i m a l ( 9 , 6 ) 
 
 	 s e t   @ t o t a l R a t i o   =   0 . 0 
 
 	 s e t   @ t o t a l T r a v e l   =   0 . 0 
 
 	 s e t   @ t r a v e l T a r g e t   =   @ r a t i o   *   @ T o t a l L e n g t h 
 
 
 
 	 - - - F o r   e a c h   l n g / l a t   p a i r   t h a t   i s n ' t   e m p t y ,   c a l c u l a t e   d i s t a n c e   f r o m   l a s t   n o n   e m p t y   p a i r . 
 
 	 - - - I s   t h e   t o t a l R a t i o   +   r a t i o   o f   t h i s   s e g m e n t   <   t h e   r a t i o   w e   a r e   l o o k i n g   f o r ? 
 
 	 - - - I f   y e s ,   a d d   t h e   r a t i o   o f   t h i s   d i s t a n c e   t o   t h e   t o t a l   r a t i o 
 
 	 - - - I f   n o ,   t r i m   t h e   r a t i o   s o   t h a t   i t   a p p l i e s   o n l y   t o   t h i s   s e g m e n t   a n d   r e t u r n   c a l c u l a t e d   p o i n t . 
 
 
 
 	 - - b u f f e r   v a r s   t o   k e e p   t h e   c o d e   a   b i t   s h o r t e r 
 
 	 d e c l a r e   @ t h i s L e n   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ t h i s R a t i o   d e c i m a l ( 2 0 , 6 ) 
 
 
 
 	 d e c l a r e   @ u s e S t a r t L o n g   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ u s e S t a r t L a t   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ u s e E n d L o n g   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ u s e E n d L a t   d e c i m a l ( 9 , 6 ) 
 
 
 
 	 d e c l a r e   @ u s e R a t i o   d e c i m a l ( 9 , 6 ) 
 
 	 
 
 	 
 
 	 - - w e ' v e   g o t   t o   d o   t h i s   1 0   t i m e s 
 
 	 i f   ( ( @ L a t 1   < >   0 )   a n d   ( @ f o u n d   =   0 )   ) 
 
 	 b e g i n 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ l o n g 1 ,   @ l a t 1 ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g   =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t   =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g     =   @ L o n g 1 
 
 	 	     s e t   @ u s e E n d L a t     =   @ L a t 1 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ L o n g 1 
 
 	 	   s e t   @ l a s t L a t   =   @ L a t 1 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 
 
 	 e n d 
 
 
 
 
 
 
 
 	 i f   ( @ L a t 2   < >   0   a n d   @ f o u n d   =   0 )   
 
 	 b e g i n 	 	 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ l o n g 2 ,   @ l a t 2 ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g     =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t     =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g   =   @ L o n g 2 
 
 	 	     s e t   @ u s e E n d L a t     =   @ L a t 2 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ L o n g 2 
 
 	 	   s e t   @ l a s t L a t   =   @ L a t 2 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 
 
 	 e n d 
 
 
 
 
 
 
 
 	 i f   ( @ L a t 3   < >   0   a n d   @ f o u n d   =   0 )   
 
 	 b e g i n 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ l o n g 3 ,   @ l a t 3 ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g     =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t     =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g     =   @ L o n g 3 
 
 	 	     s e t   @ u s e E n d L a t   =   @ L a t 3 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ L o n g 3 
 
 	 	   s e t   @ l a s t L a t   =   @ L a t 3 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 	 
 
 	 e n d 
 
 
 
 
 
 
 
 	 i f   ( @ L a t 4   < >   0   a n d   @ f o u n d   =   0 )   
 
 	 b e g i n 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ l o n g 4 ,   @ l a t 4 ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g     =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t     =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g     =   @ L o n g 4 
 
 	 	     s e t   @ u s e E n d L a t     =   @ L a t 4 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ L o n g 4 
 
 	 	   s e t   @ l a s t L a t   =   @ L a t 4 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 
 
 	 e n d 
 
 
 
 
 
 	 i f   ( @ L a t 5   < >   0   a n d   @ f o u n d   =   0 )   
 
 	 b e g i n 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ l o n g 5 ,   @ l a t 5 ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g     =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t     =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g     =   @ L o n g 5 
 
 	 	     s e t   @ u s e E n d L a t     =   @ L a t 5 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ L o n g 5 
 
 	 	   s e t   @ l a s t L a t   =   @ L a t 5 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 	 
 
 	 e n d 
 
 
 
 
 
 	 i f   ( @ L a t 6   < >   0   a n d   @ f o u n d   =   0 )   
 
 	 b e g i n 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ l o n g 6 ,   @ l a t 6 ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g     =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t     =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g     =   @ L o n g 6 
 
 	 	     s e t   @ u s e E n d L a t     =   @ L a t 6 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ L o n g 6 
 
 	 	   s e t   @ l a s t L a t   =   @ L a t 6 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 
 
 	 e n d 
 
 
 
 
 
 
 
 	 i f   ( @ L a t 7   < >   0   a n d   @ f o u n d   =   0 )   
 
 	 b e g i n 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ l o n g 7 ,   @ l a t 7 ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g     =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t     =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g     =   @ L o n g 7 
 
 	 	     s e t   @ u s e E n d L a t     =   @ L a t 7 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ L o n g 7 
 
 	 	   s e t   @ l a s t L a t   =   @ L a t 7 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 
 
 	 e n d 
 
 
 
 
 
 
 
 
 
 	 i f   ( @ L a t 8   < >   0   a n d   @ f o u n d   =   0 )   
 
 	 b e g i n 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ l o n g 8 ,   @ l a t 8 ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g     =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t     =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g     =   @ L o n g 8 
 
 	 	     s e t   @ u s e E n d L a t     =   @ L a t 8 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ L o n g 8 
 
 	 	   s e t   @ l a s t L a t   =   @ L a t 8 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 
 
 	 e n d 
 
 
 
 
 
 
 
 
 
 	 i f   ( @ L a t 9   < >   0   a n d   @ f o u n d   =   0 )   
 
 	 b e g i n 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ l o n g 9 ,   @ l a t 9 ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g     =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t     =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g     =   @ L o n g 9 
 
 	 	     s e t   @ u s e E n d L a t     =   @ L a t 9 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ L o n g 9 
 
 	 	   s e t   @ l a s t L a t   =   @ L a t 9 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 
 
 	 e n d 
 
 
 
 
 
 
 
 
 
 	 i f   ( @ L a t 1 0   < >   0   a n d   @ f o u n d   =   0 )   
 
 	 b e g i n 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ l o n g 2 ,   @ l a t 2 ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g     =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t     =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g     =   @ L o n g 1 0 
 
 	 	     s e t   @ u s e E n d L a t     =   @ L a t 1 0 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ L o n g 1 0 
 
 	 	   s e t   @ l a s t L a t   =   @ L a t 1 0 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 
 
 	 e n d 
 
 	 
 
 
 
 	 i f   ( @ f o u n d   =   0 ) 
 
 	 b e g i n 
 
 	 	 s e t   @ t h i s L e n   =   d b o . f n L i n e D i s t a n c e ( @ t o l n g ,   @ t o l a t ,   @ l a s t L n g ,   @ l a s t L a t ) 
 
 	 	 s e t   @ t h i s R a t i o   =   @ t h i s L e n   /   @ T o t a l L e n g t h 
 
 
 
 	 	 i f   ( @ t h i s L e n   +   @ t o t a l T r a v e l   > =   @ t r a v e l T a r g e t ) 
 
 	 	 b e g i n 
 
 	 	     s e t   @ u s e S t a r t L o n g     =   @ l a s t L n g 
 
 	 	     s e t   @ u s e S t a r t L a t     =   @ l a s t L a t 
 
 	 	     s e t   @ u s e E n d L o n g     =   @ t o l n g 
 
 	 	     s e t   @ u s e E n d L a t     =   @ t o l a t 
 
 	 	     
 
 	 	     s e t   @ u s e R a t i o   =   @ t h i s R a t i o 
 
 	 	     s e t   @ f o u n d   =   1 
 
 	 	 e n d 
 
 	 	 e l s e 
 
 	 	 b e g i n 
 
 	 	   s e t   @ t o t a l R a t i o   =   @ t o t a l R a t i o   +   @ t h i s R a t i o 
 
 	 	   s e t   @ l a s t L n g   =   @ t o l n g 
 
 	 	   s e t   @ l a s t L a t   =   @ t o l a t 
 
 	 	   s e t   @ t o t a l T r a v e l   =   @ t o t a l T r a v e l   +   @ t h i s L e n 
 
 	 	 e n d 
 
 	 e n d 
 
 
 
 	 d e c l a r e   @ l o n   d e c i m a l ( 9 , 6 ) 
 
 	 d e c l a r e   @ l a t   d e c i m a l ( 9 , 6 ) 
 
 
 	 d e c l a r e   @ r e l   d e c i m a l ( 9 , 6 ) 	 
 
 
 
 	 s e t   @ r e l   =   ( @ R a t i o   -   @ t o t a l R a t i o )   /   @ u s e R a t i o 
 
 	 	 
 
 	 d e c l a r e   @ l o n D i s t   d e c i m a l ( 9 , 6 )   
 
 	 d e c l a r e   @ l a t D i s t   d e c i m a l ( 9 , 6 ) 
 	 s e t   @ l o n D i s t   =   @ u s e E n d L o n g   -   @ u s e S t a r t L o n g 
 
 	 s e t   @ l a t D i s t   =   @ u s e E n d L a t   -   @ u s e S t a r t L a t 
 
 / * 
 
 	 s e t   @ l o n   =   @ u s e S t a r t L o n g   +   ( @ r e l   *   @ l o n D i s t ) 
 
 	 s e t   @ l a t   =   @ u s e S t a r t L a t   +   ( @ r e l   *   @ l a t D i s t ) 
 
 * / 
 
 	 s e t   @ l o n   =   @ u s e E n d L o n g   -   ( @ r e l   *   @ l o n D i s t ) 
 
 	 s e t   @ l a t   =   @ u s e E n d L a t   -   ( @ r e l   *   @ l a t D i s t ) 
 
 	 
 
 	 i n s e r t   i n t o   @ L o n g L a t 	 
 
 	 	 s e l e c t   @ l o n ,   @ l a t 
 
 	 R E T U R N   
 
 E N D 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O F F   
 
 G O 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 / * 
 
    2 0 0 5   J o h n   S a m p l e 
 
 
 
         T h i s   p r o g r a m   i s   f r e e   s o f t w a r e ;   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
         i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
         t h e   F r e e   S o f t w a r e   F o u n d a t i o n ;   e i t h e r   v e r s i o n   2   o f   t h e   L i c e n s e ,   o r 
 
         ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
 
 
         T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
         b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
         M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
         G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
 
 
 * / 
 
 
 
 / * 
 
 T h i s   f u n c t i o n   w i l l   f i n d   t h e   c l o s e s t   n o d e   t o   t h e   g i v e n   l o n g / l a t 
 
 I t   w i l l   u s u a l l y   r e t u r n   m o r e   t h a n   o n e   r o w   s i n c e   t h e   b e g i n n i n g / e n d   o f   o n e   n o d e   i s   a l m o s t   a l w a y s   t h e   b e g i n n i n g / e n d   o f   a t   l e a s t   o n e   o t h e r 
 
 H o w e v e r ,   t h e   L o n g / L a t   r e t u r n e d   f o r   a l l   r e c o r d s   w i l l   a l m o s t   a l w a y s   b e   t h e   s a m e   u n l e s s   w e   h a p p e n   t o   q u e r y   a   p o i n t   w h i c h   i s   e q u i d i s t a n t   f r o m   2   o r   m o r e   c o m p l e t e l y   u n c h a i n e d   n o d e s . 
 
 Y o u   c a n   q u e r y   t h e   r e t u r n   t a b l e   f o r   d i s t i n c t   n a m e s   t o   g e t   t h e   t i t l e   o f   t h e   i n t e r s e c t i o n   i f   o n e   e x i s t s . 
 
 I f   y o u   a r e   u s i n g   a   d a t a b a s e   w i t h   m o r e   t h a n   o n e   t i g e r / l i n e   c o u n t y   s e t ,   u s e   t h e   s t a t e l / s t a t e r   a n d   c o u n t y l / c o u n t y r   F I P s   c o d e s   f o r   g e n e r a l   l o c a t i o n   i n f o 
 
 * / 
 
 
 
 C R E A T E           f u n c t i o n   f n R e v e r s e G e o c o d e ( @ L o n g i t u d e   d e c i m a l ( 9 , 6 ) ,   @ L a t i t u d e   d e c i m a l ( 9 , 6 ) ) 
 
 R E T U R N S   @ L o c a t i o n   T A B L E   
 
 	 ( 
 
 	 T L I D   v a r c h a r ( 5 0 ) , 
 
 	 L o n g i t u d e   D e c i m a l ( 9 , 6 ) ,   - - T h e s e   a r e   t h e   c l o s e s t   n o d e   p o i n t s ,   t h e y   c o u l d   b e   f r l o n g / f r l a t   o r   t o l o n g / t o l a t 
 
 	 L a t i t u d e   D e c i m a l ( 9 , 6 ) ,   
 
 	 f e d i r p   v a r c h a r ( 2 ) , 
 
 	 f e n a m e   v a r c h a r ( 5 0 ) , 
 
 	 f e t y p e   v a r c h a r ( 1 0 ) , 
 
 	 f r a d d r   i n t , 
 
 	 t o a d d r   i n t , 
 
 	 f r a d d l   i n t , 
 
 	 t o a d d l   i n t , 
 
 	 z i p l   i n t , 
 
 	 z i p r   i n t , 
 
 	 f r l a t   i n t , 
 
 	 f r l o n g   i n t , 
 
 	 t o l a t   i n t , 
 
 	 t o l o n g   i n t , 
 
 	 c o u n t y l   i n t , 
 
 	 c o u n t y r   i n t , 
 
 	 s t a t e l   i n t , 
 
 	 s t a t e r   i n t 
 
 	 ) 
 
 A S 
 
 B E G I N 
 
 
 
 d e c l a r e   @ f r o m d e c   i n t   
 
 s e t   @ f r o m d e c   =   1 0 0 0 0 0 0 
 
 d e c l a r e   @ t o d e c i m a l   d e c i m a l ( 9 , 6 ) 
 
 s e t   @ t o d e c i m a l   =   0 . 0 0 0 0 0 1 
 
 d e c l a r e   @ L a t   i n t   
 
 d e c l a r e   @ L n g   i n t 
 
 d e c l a r e   @ s w a y   i n t 
 
 
 
 s e t   @ s w a y   = 0 . 0 1 4 4 9 2 7 5   *   1 0 0 0 0 0 
 
 s e t   @ L a t   =   @ L a t i t u d e   *   @ f r o m d e c 
 
 s e t   @ L n g   =   @ L o n g i t u d e   *   @ f r o m d e c 
 
 
 
 i n s e r t   i n t o   @ L o c a t i o n 
 
 s e l e c t   	 T L I D ,   f r l o n g   *   @ t o d e c i m a l   a s   L o n g i t u d e ,   f r l a t     *   @ t o d e c i m a l   a s   L a t i t u d e ,   f e d i r p ,   f e n a m e ,   f e t y p e ,   f r a d d r ,   t o a d d r ,   f r a d d l ,   t o a d d l ,   z i p l ,   z i p r ,   f r l a t ,   f r l o n g ,   t o l a t ,   t o l o n g ,   c o u n t y l ,   c o u n t y r ,   s t a t e l ,   s t a t e r   
 
 	 f r o m   t i g e r _ 0 1   W I T H   ( n o l o c k ,   i n d e x ( I D X _ F R L A T ) )   w h e r e   ( f r l a t   <   ( @ l a t   +   @ s w a y )   a n d   f r l a t   >   ( @ l a t   -   @ s w a y )   a n d   f r l o n g   <   ( @ l n g   +   @ s w a y )   a n d   f r l o n g   >   ( @ l n g   -   @ s w a y ) )   a n d   a b s ( f r l a t   -   @ L a t )   +     a b s ( f r l o n g   -   @ L n g )   =   ( s e l e c t   m i n ( a b s ( f r l a t   -   @ L a t )   +   a b s ( f r l o n g   -   @ L n g ) )   f r o m   t i g e r _ 0 1   W I T H   ( n o l o c k ,   i n d e x ( I D X _ F R L A T ) )   w h e r e   ( f r l a t   <   ( @ l a t   +   @ s w a y )   a n d   f r l a t   >   ( @ l a t   -   @ s w a y )   a n d   f r l o n g   <   ( @ l n g   +   @ s w a y )   a n d   f r l o n g   >   ( @ l n g   -   @ s w a y ) )         ) 
 
 U N I O N 
 
 s e l e c t   T L I D ,   t o l o n g   *   @ t o d e c i m a l   a s   L o n g i t u d e ,   t o l a t   *   @ t o d e c i m a l   a s   L a t i t u d e ,   f e d i r p ,   f e n a m e ,   f e t y p e ,   f r a d d r ,   t o a d d r ,   f r a d d l ,   t o a d d l ,   z i p l ,   z i p r ,   f r l a t ,   f r l o n g ,   t o l a t ,   t o l o n g ,   c o u n t y l ,   c o u n t y r ,   s t a t e l ,   s t a t e r   
 
 	 f r o m   t i g e r _ 0 1   W I T H   ( n o l o c k ,   i n d e x ( I D X _ T O L A T ) )   w h e r e   ( t o l a t   <   ( @ l a t   +   @ s w a y )   a n d   t o l a t   >   ( @ l a t   -   @ s w a y )   a n d   t o l o n g   <   ( @ l n g   +   @ s w a y )   a n d   t o l o n g   >   ( @ l n g   -   @ s w a y ) )   a n d   a b s ( t o l a t   -   @ L a t )   +     a b s ( t o l o n g   -   @ L n g )   =   ( s e l e c t   m i n ( a b s ( t o l a t   -   @ L a t )   +   a b s ( t o l o n g   -   @ L n g ) )   f r o m   t i g e r _ 0 1   W I T H   ( n o l o c k ,   i n d e x ( I D X _ T O L A T ) )   w h e r e   ( t o l a t   <   ( @ l a t   +   @ s w a y )   a n d   t o l a t   >   ( @ l a t   -   @ s w a y )   a n d   t o l o n g   <   ( @ l n g   +   @ s w a y )   a n d   t o l o n g   >   ( @ l n g   -   @ s w a y ) )         ) 
 
 
 
 r e t u r n 
 
 E N D 
 
 
 
 
 
 
 
 
 
 
 
 G O 
 
 S E T   Q U O T E D _ I D E N T I F I E R   O F F   
 
 G O 
 
 S E T   A N S I _ N U L L S   O N   
 
 G O 
 
 
 
 C R E A T E   T A B L E   [ d b o ] . [ F I P S 5 5 ]   ( 
 
 	 [ S T A T E ]   [ i n t ]   N U L L   , 
 
 	 [ P L A C E ]   [ i n t ]   N U L L   , 
 
 	 [ S T A T E _ A L P H A ]   [ v a r c h a r ]   ( 2 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N O T   N U L L   , 
 
 	 [ N U M _ C O U N T I E S ]   [ i n t ]   N U L L   , 
 
 	 [ C R S N ]   [ i n t ]   N U L L   , 
 
 	 [ C L A S S ]   [ v a r c h a r ]   ( 2 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ P L A C E _ N A M E ]   [ v a r c h a r ]   ( 5 2 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N O T   N U L L   , 
 
 	 [ C O U N T Y ]   [ i n t ]   N O T   N U L L   , 
 
 	 [ C O U N T Y _ N A M E ]   [ v a r c h a r ]   ( 2 2 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ P A R T _ O F ]   [ i n t ]   N U L L   , 
 
 	 [ O T H E R _ N A M E ]   [ i n t ]   N U L L   , 
 
 	 [ Z I P ]   [ i n t ]   N U L L   , 
 
 	 [ P O S T A L _ N A M E ]   [ v a r c h a r ]   ( 2 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ Z I P _ R A N G E ]   [ i n t ]   N U L L   , 
 
 	 [ G S A ]   [ i n t ]   N U L L   , 
 
 	 [ M R F ]   [ i n t ]   N U L L   , 
 
 	 [ M S A ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 1 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 2 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 3 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 4 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 5 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 6 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 7 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 8 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 9 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 1 0 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 1 1 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 1 2 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 1 3 ]   [ i n t ]   N U L L   , 
 
 	 [ C D _ 1 4 ]   [ i n t ]   N U L L   
 
 )   O N   [ P R I M A R Y ] 
 
 G O 
 
 
 
 C R E A T E   T A B L E   [ T I G E R _ 0 1 ]   ( 
 
 	 [ T L I D ]   [ i n t ]   N O T   N U L L   , 
 
 	 [ F E D I R P ]   [ v a r c h a r ]   ( 2 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ F E N A M E ]   [ v a r c h a r ]   ( 3 0 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ F E T Y P E ]   [ v a r c h a r ]   ( 4 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ F E D I R S ]   [ v a r c h a r ]   ( 2 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ C F C C ]   [ v a r c h a r ]   ( 3 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ F R A D D L ]   [ i n t ]   N U L L   , 
 
 	 [ T O A D D L ]   [ i n t ]   N U L L   , 
 
 	 [ F R A D D R ]   [ i n t ]   N U L L   , 
 
 	 [ T O A D D R ]   [ i n t ]   N U L L   , 
 
 	 [ Z I P L ]   [ i n t ]   N U L L   , 
 
 	 [ Z I P R ]   [ i n t ]   N U L L   , 
 
 	 [ S T A T E L ]   [ i n t ]   N U L L   , 
 
 	 [ S T A T E R ]   [ i n t ]   N U L L   , 
 
 	 [ C O U N T Y L ]   [ i n t ]   N U L L   , 
 
 	 [ C O U N T Y R ]   [ i n t ]   N U L L   , 
 
 	 [ P L A C E L ]   [ i n t ]   N U L L   , 
 
 	 [ P L A C E R ]   [ i n t ]   N U L L   , 
 
 	 [ F R L O N G ]   [ i n t ]   N U L L   , 
 
 	 [ F R L A T ]   [ i n t ]   N U L L   , 
 
 	 [ T O L O N G ]   [ i n t ]   N U L L   , 
 
 	 [ T O L A T ]   [ i n t ]   N U L L   
 
 )   O N   [ P R I M A R Y ] 
 
 G O 
 
 
 
 C R E A T E   T A B L E   [ T I G E R _ 0 1 _ M I N _ T E M P ]   ( 
 
 	 [ T L I D ]   [ i n t ]   N O T   N U L L   , 
 
 	 [ F E D I R P ]   [ v a r c h a r ]   ( 2 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ F E N A M E ]   [ v a r c h a r ]   ( 3 0 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ F E T Y P E ]   [ v a r c h a r ]   ( 4 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ F E D I R S ]   [ v a r c h a r ]   ( 2 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ C F C C ]   [ v a r c h a r ]   ( 3 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ F R A D D L ]   [ i n t ]   N U L L   , 
 
 	 [ T O A D D L ]   [ i n t ]   N U L L   , 
 
 	 [ F R A D D R ]   [ i n t ]   N U L L   , 
 
 	 [ T O A D D R ]   [ i n t ]   N U L L   , 
 
 	 [ Z I P L ]   [ i n t ]   N U L L   , 
 
 	 [ Z I P R ]   [ i n t ]   N U L L   , 
 
 	 [ S T A T E L ]   [ i n t ]   N U L L   , 
 
 	 [ S T A T E R ]   [ i n t ]   N U L L   , 
 
 	 [ C O U N T Y L ]   [ i n t ]   N U L L   , 
 
 	 [ C O U N T Y R ]   [ i n t ]   N U L L   , 
 
 	 [ P L A C E L ]   [ i n t ]   N U L L   , 
 
 	 [ P L A C E R ]   [ i n t ]   N U L L   , 
 
 	 [ F R L O N G ]   [ i n t ]   N U L L   , 
 
 	 [ F R L A T ]   [ i n t ]   N U L L   , 
 
 	 [ T O L O N G ]   [ i n t ]   N U L L   , 
 
 	 [ T O L A T ]   [ i n t ]   N U L L   
 
 )   O N   [ P R I M A R Y ] 
 
 G O 
 
 
 
 
 
 C R E A T E   T A B L E   [ d b o ] . [ T I G E R _ 0 2 ]   ( 
 
 	 [ R T ]   [ v a r c h a r ]   ( 1 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ V E R S I O N ]   [ i n t ]   N U L L   , 
 
 	 [ T L I D ]   [ i n t ]   N U L L   , 
 
 	 [ R T S Q ]   [ i n t ]   N U L L   , 
 
 	 [ L O N G 1 ]   [ i n t ]   N U L L   , 
 
 	 [ L A T 1 ]   [ i n t ]   N U L L   , 
 
 	 [ L O N G 2 ]   [ i n t ]   N U L L   , 
 
 	 [ L A T 2 ]   [ i n t ]   N U L L   , 
 
 	 [ L O N G 3 ]   [ i n t ]   N U L L   , 
 
 	 [ L A T 3 ]   [ i n t ]   N U L L   , 
 
 	 [ L O N G 4 ]   [ i n t ]   N U L L   , 
 
 	 [ L A T 4 ]   [ i n t ]   N U L L   , 
 
 	 [ L O N G 5 ]   [ i n t ]   N U L L   , 
 
 	 [ L A T 5 ]   [ i n t ]   N U L L   , 
 
 	 [ L O N G 6 ]   [ i n t ]   N U L L   , 
 
 	 [ L A T 6 ]   [ i n t ]   N U L L   , 
 
 	 [ L O N G 7 ]   [ i n t ]   N U L L   , 
 
 	 [ L A T 7 ]   [ i n t ]   N U L L   , 
 
 	 [ L O N G 8 ]   [ i n t ]   N U L L   , 
 
 	 [ L A T 8 ]   [ i n t ]   N U L L   , 
 
 	 [ L O N G 9 ]   [ i n t ]   N U L L   , 
 
 	 [ L A T 9 ]   [ i n t ]   N U L L   , 
 
 	 [ L O N G 1 0 ]   [ i n t ]   N U L L   , 
 
 	 [ L A T 1 0 ]   [ i n t ]   N U L L   
 
 )   O N   [ P R I M A R Y ] 
 
 G O 
 
 
 
 C R E A T E   T A B L E   [ d b o ] . [ T I G E R _ T Y P E S ]   ( 
 
 	 [ T Y P E _ I D ]   [ i n t ]   N O T   N U L L   , 
 
 	 [ T I G E R _ T Y P E ]   [ v a r c h a r ]   ( 4 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   , 
 
 	 [ L O N G _ N A M E ]   [ v a r c h a r ]   ( 1 5 )   C O L L A T E   S Q L _ L a t i n 1 _ G e n e r a l _ C P 1 _ C I _ A S   N U L L   
 
 )   O N   [ P R I M A R Y ] 
 
 G O 
 
 
 
 